/**
 * @param {number[]} nums
 * @return {number}
*/
var massage = function(nums) {
  if(nums.length == 0) return 0;
  if(nums.length < 3) return Math.max(...nums);
  let dp = new Array(nums.length).fill(0), max = 0;
  dp[0] = nums[0], dp[1] = nums[1];
  max = Math.max(dp[0], dp[1]);
  for(let i = 2; i < nums.length; i++) {
    if(i == 2) {
      dp[i] = dp[i - 2] + nums[i];
    } else {
      dp[i] = Math.max(dp[i - 2] + nums[i], dp[i - 3] + nums[i]);
    }
    max = Math.max(max, dp[i]);
  }
  return max;
};
let nums = [1,2,3,1];
console.log(massage(nums));
nums = [2,7,9,3,1];
console.log(massage(nums));
nums = [2,1,4,5,3,1,1,3];
console.log(massage(nums));
nums = [1,3,1];
console.log(massage(nums));
